package com.hotcode;

/**
 * @Author: huangzhigao
 * @Date: 2023/2/25 19:05
 */
public class leecode198 {
    public int rob(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];

        for (int i = 0; i < n; i++) {
            if (i == 0) {
                dp[i] = nums[i];
            } else if (i == 1) {
                dp[i] = Math.max(dp[i - 1], nums[i]);
            } else {
                dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 1]);
            }
        }

        return dp[n - 1];
    }
}
